{% extends 'IcsocUIBundle::page.html.twig' %}
{% from 'IcsocUIBundle:Macro:grid.html.twig' import gridWidth,gridNav,gridConfig,formInline %}
{% block stylesheet %}
    {{ parent() }}
    {% stylesheets
    '@datepicker_css'
    '@jqgird_css'
    '@gritter_css'
    filter='cssrewrite' filter='uglifycss'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}

{% block content %}
    {{ formInline(options) }}
    <table id="grid-table"></table>
    <div id="grid-pager"></div>
{% endblock %}
{% block footer %}
    {% javascripts
    '@datepicker_js'
    '@jqgird_js'
    '@gritter_js'
    '@common_js'
    filter='uglifyjs'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    <script type="text/javascript">
        $(function () {
            $("#start_time").datetimepicker({locale:'zh-cn',format:'YYYY-MM-DD',widgetPositioning:{horizontal:'left'}});
            $("#end_time").datetimepicker({locale:'zh-cn',format:'YYYY-MM-DD',widgetPositioning:{horizontal:'left'}});
        });
        jQuery(function($) {
            {{ gridWidth() }}
            jQuery(grid_selector).jqGrid({
                url: "{{ path('icsoc_ivr_sta_redis') }}",  //数据；
                mtype: 'POST',
                datatype: "json",
                postData: {param:jsonToString(getCondition())},
                hidegrid:false,
                colModel:[
                    {name:'ivr_name',index:'ivr_name',label:'流程名称',width:100,editable: true, sortable:false, key:true, fixed:true},
                    {name:'deal_date',index:'deal_date',label:'日期',width:100,editable: true, sortable:false, key:true, fixed:true},
                    {% for k,field in ivrtitle %}
                        {name:'{{ k }}',index:'{{ k }}',label:'{{ field }}',width:100,editable: true, sortable:false, fixed:true},
                    {% endfor %}
                ],
                {{ gridConfig() }}
                height: '326',
                sortname: 'id',
                editurl: "{{ path('icsoc_ivr_delete_data') }}",//nothing is saved 定义对form编辑时的url
                caption: "{{ 'Ivr Sta Report List'|trans }}"//表格名称
            });
            {{ gridNav(false,false,false,false,true,false) }}
            jQuery(grid_selector).navButtonAdd(
                    pager_selector,
                    {
                        caption:'{{ 'Export Csv'|trans }}',
                        buttonicon:'ace-icon fa fa-file-excel-o  primary',
                        onClickButton:function() {
                            location.href = "{{ path('icsoc_ivr_sta_redis', {'export': 'csv'})|raw }}&param="+jsonToString(getCondition());
                        }
                    }
            ).navButtonAdd(
                    pager_selector,
                    {
                        caption:'{{ 'Export Excel'|trans }}',
                        buttonicon:'ace-icon fa fa-file-excel-o  primary',
                        onClickButton:function() {
                            location.href = "{{ path('icsoc_ivr_sta_redis', {'export': 'excel'})|raw }}&param="+jsonToString(getCondition());
                        }
                    }
            );
            $('#grid-pager_left').removeAttr('style');
        });

        $("#ivr_id").change(function(){
            var ivr_id = $("#ivr_id option:selected").val();
            var startTime = $('#start_time').val();
            var endTime = $('#end_time').val();
            location.href = "{{ path('icsoc_ivr_sta') }}"+"?ivr_id="+ivr_id+"&start_time="+startTime+"&end_time="+endTime;
        });

        /**
         * 搜索
         */
        function search()
        {
            $('#grid-table').setGridParam({page:1,postData:{param:jsonToString(getCondition())}}).trigger("reloadGrid");
        }

        /**
         * 获取搜索条件
         */
        function getCondition()
        {
            var $start_time = $('#start_time');
            var $end_time = $('#end_time');
            if (!$start_time.val()) {
                $start_time.parent().parent().addClass('has-error');
                $start_time.focus();
                return;
            }
            if (!$end_time.val()) {
                $end_time.parent().parent().addClass('has-error');
                $end_time.focus();
                return;
            }
            var param = {};
            param.start_time =  $.trim($('#start_time').val());
            param.end_time =  $.trim($('#end_time').val());
            param.ivr_id =  $('#ivr_id option:selected').val();
            return param;
        }
    </script>
{% endblock %}